package insulin

import (
	"github.com/bgmp/config"
	"github.com/bgmp/handler"
	"github.com/bgmp/model"
	"github.com/gin-gonic/gin"
)

func (b Base) GetInsulinTherapy(c *gin.Context, req *GetInsulinTherapyRequest) *GetInsulinTherapyResponse {
	t := model.InsulinTherapy{
		UserId: req.PatientId,
	}
	err := t.GetBefore(config.DB, req.Before)
	if err != nil {
		handler.Errorf(c, err.Error())
		return nil
	}
	return &GetInsulinTherapyResponse{
		Therapy: t,
	}
}

type GetInsulinTherapyRequest struct {
	PatientId uint       `json:"patient_id"`
	Before    model.Time `json:"before"`
}

type GetInsulinTherapyResponse struct {
	Therapy model.InsulinTherapy `json:"therapy"`
}
